<template>
  <el-dialog title="种树" :visible.sync="dialogVisible" width="250px">
    <el-form ref="onok" :model="form">
      <el-form-item prop="count" :rules="{ required: true, message: '不能为空', trigger: 'change' }">
        <el-input-number v-model="form.count" :min="0" />
      </el-form-item>
    </el-form>
    <div style="text-align: center">
      <el-button style="margin-top: 20px" type="primary" @click="onSubmit('onok')">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import { handelRegister } from '../../../request/facilityList'
export default {
  props: ['selectValue', 'chooseItem'],
  data() {
    return {
      dialogVisible: false,
      form: {
        count: undefined
      }
    }
  },
  methods: {
    async onSubmit(name) {
      this.$refs[name].validate((valid) => {
        if (valid) this.handelRegister()
      })
    },
    handelOpen() {
      this.dialogVisible = true
    },
    handelClose() {
      this.dialogVisible = false
    },
    async handelRegister() {
      this.$http.post(`/api/cloud_curbs/batch_register`, {
        ips: this.selectValue,
        number: this.form.count,
        containerIps: this.chooseItem.map(ele => {
          return ele.containerIp
        })
      }).then(res => {
        if (res.success) {
          this.$success('操作成功')
        }
      })
      this.handelClose()
    }
  }
}
</script>
